package org.learn.java.mq.consumer;

import java.util.Properties;

import javax.sound.midi.Receiver;

import org.learn.java.mq.MqContent;
import org.learn.java.mq.listener.MyMessgeListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.MessageListener;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.PropertyValueConst;

public class Consumer2 {

	public static Logger logger = LoggerFactory.getLogger(Consumer2.class);

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		generalreceive(); // 普通消息接受
	}

	public static void generalreceive() {
		logger.debug("----Consumer2.generalreceive----");
		// 配置producer参数
		Properties properties = new Properties();
		properties.put(PropertyKeyConst.ConsumerId, "CID_t_2");
		properties.put(PropertyKeyConst.AccessKey, MqContent.MQ_AccessKey );
		properties.put(PropertyKeyConst.SecretKey,
				"7JbgLiklyNxmkXQkM0iBKWuyqNvnjU");
		/*properties.put(PropertyKeyConst.MessageModel,
                PropertyValueConst.BROADCASTING);*/
		Consumer consumer = ONSFactory.createConsumer(properties);

		MessageListener listener = new MyMessgeListener();

		consumer.subscribe("Topic_t_1", "m2", listener);

		consumer.start();
		logger.debug("consumer启动成功");

	}
}
